<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>付款</title>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--extended-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<div class="project whitebg" style="width: 500px;height: 300px;">
    <div>
        <input type="hidden" id="projectId" value="${projectId}">
        <h3>工程款支付</h3>
        <form action="" class="layui-form" style="margin-top: 50px;">
            <#if '${zftype}'=='1' >
                <ul class="clearfix">
                    <li class="clearfix">
                        <label><span class="red">*</span> 金额</label>
                        <input type="hidden" id="id" value="${id}">
                        <input type="hidden" id="projectId" value="${projectId}">
                        <input type="hidden" id="fbcode" value="${fbcode}">
                        <input type="hidden" id="fileId" value="${fileId}">
                        <input type="hidden" id="isSubmit" value="0">
                        <input type="text" name="payMoney" id="payMoney" lay-verify="payMoney" placeholder="请输入金额">元
                    </li>
                </ul>
            </#if>
            <#if '${zftype}'=='2' >
                <ul class="clearfix">
                    <li class="clearfix">
                        <div class="layui-col-md3 w80p" style="height: 36px;">
                            <select  id="zfcs"
                                    style="width: 30% !important;"      >

                                <option value="">请选择支付次数</option>
                                <#list listpay as vo>
                                    <option value="${vo.sppId}">${vo.sppNo}</option>
                                </#list>
                            </select>
                        </div>
                    </li>
                    <li class="clearfix">
                        <input type="hidden" id="projectId" value="${projectId}">
                        <input type="hidden" id="fileId" value="${fileId}">
                        <input type="text" name="jlPayMoney" style="width: 350px"  id="jlPayMoney" placeholder="请输入支付金额">元
                    </li>
                    <li class="clearfix">
                        <input type="text" name="jlInvoiceMoney"  style="width: 350px"  id="jlInvoiceMoney" lay-verify="jlInvoiceMoney"
                               placeholder="请输入发票金额">元
                    </li>

                </ul>
            </#if>

            <div class="popUpBtn center">
                <button type="button" class="blue bgnone close">关闭</button>
                <button type="button" class="bluebg white submit" lay-submit lay-filter="submit">提交</button>
            </div>
        </form>

    </div>
</div>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script type="text/javascript" src="${re.contextPath}/plugin/system/supervisor/projectManager.js"></script>
<script type="text/javascript">
    var layer;
    var form;
    var laydate;
    layui.use(['form', 'laydate', 'layer'], function () {
        layer = layui.layer;
        form = layui.form;
        console.log(form);
        //监听提交
        form.on('submit(submit)', function (data) {
            var zftype='${zftype}';
            var json="";
            if(zftype=='2'){
                // 监理支付申请
                var zfcs = $("#zfcs").val();
                console.log(zfcs);
                if(zfcs==null || zfcs=="" ){
                    layer.msg("请选择支付次数", {icon: 2});
                    return;
                }
                var jlPayMoney = $("#jlPayMoney").val();
                if(jlPayMoney==null || jlPayMoney=="" ){
                    layer.msg("请输入支付金额", {icon: 2});
                    return;
                }
                var jlInvoiceMoney = $("#jlInvoiceMoney").val();
                if(jlInvoiceMoney==null || jlInvoiceMoney=="" ){
                    layer.msg("请输入发票金额", {icon: 2});
                    return;
                }
                var reg = /^[0-9][0-9]*([.][0-9]+)?$/;
                if (!jlPayMoney.match(reg)) {
                    layer.msg("请填写数字", {icon: 2});
                    return;
                }
                if (!jlInvoiceMoney.match(reg)) {
                    layer.msg("请填写数字", {icon: 2});
                    return;
                }
                 json = {
                    sppId:zfcs,//支付表Id
                    fileId: '${fileId}',
                    projectId: '${projectId}',
                    jlPayMoney: jlPayMoney,
                    jlInvoiceMoney:jlInvoiceMoney,
                    type:'2'
                }
                console.log(json);

            }else{
                // 承建单位付款申请
                // 承建单位Id
                var id = $("#id").val();
                var payMoney = $("#payMoney").val();
                if (payMoney == null || payMoney == "") {
                    layer.msg("请填写金额", {icon: 2});
                    return;
                }
                var reg = /^[0-9][0-9]*([.][0-9]+)?$/;
                if (!payMoney.match(reg)) {
                    layer.msg("请填写数字", {icon: 2});
                    return;
                }
                 json = {
                    id: id,
                    fileId: '${fileId}',
                    projectId: '${projectId}',
                    paymoney: payMoney,
                    type:'1'
                }
            }
            layer.confirm('确定金额输入正确？', function (index) {
                $('.submit').addClass("layui-btn-disabled").attr("disabled", true);
                layerAjax('/supervisor/projectManager/saveFkje', json, '', function (d) {
                    $("#isSubmit").val("1");
                    if (d.flag == true) {
                        layer.msg(d.msg, {icon: 1});
                        if(json.type=='2'){
                            var jlzfys=$(parent.document).find("#jlzf");
                            var jlmoney="";
                            if($(parent.document).find("#jlzf").html()){
                                jlmoney=parseFloat($(parent.document).find("#jlzf").html())+parseFloat(json.jlPayMoney)
                            }else{
                                jlmoney=json.jlPayMoney;
                            }
                            $(jlzfys).html(jlmoney);
                        }else if(json.type=='1'){
                            var cjzfys=$(parent.document).find("#cjzf${fbcode}");
                            var cjmoney="";
                            if($(parent.document).find("#cjzf${fbcode}").html()){
                                cjmoney=parseFloat($(parent.document).find("#cjzf${fbcode}").html())+parseFloat(json.paymoney)
                            }else{
                                cjmoney=json.paymoney;
                            }
                            $(cjzfys).html(cjmoney);
                        }

                        //关闭窗口
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 2000)
                    } else {
                        $('.submit').removeClass("layui-btn-disabled").attr("disabled", false);
                        layer.msg(d.msg, {icon: 2});
                    }
                    console.log(d);
                });

            });

            return false;

        });
    });
    $('.close').click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });

</script>

</body>

</html>
